﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:skin="clr-namespace:UBCon.Ribbon.SkinManagers"
                    xmlns:ubcr="clr-namespace:UBCon.Ribbon">

    <Thickness x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=ButtonsPanelMargin}">0,0,5,0</Thickness>
    
    <!--Minimize button template-->
    <ControlTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=DefaultCaptioButtonTemplate}"
                     TargetType="{x:Type ubcr:RibbonButton}">
        <ubcr:RibbonChrome  InnerBorderCornerRadius="0" 
                           InnerBorderThickness="0"  
                           BorderThickness="1"
                           BorderBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=TransparentBrush}}" 
                           Background="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=TransparentBrush}}"  
                           MouseOverBorderBrush="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=SelectedBorderBrush}}"  
                           RenderMouseOver="{TemplateBinding IsMouseOver}"
                           MouseOverBackgroundBrush="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=SelectedTabItemBrush}}"
                           RenderPressed="{TemplateBinding IsPressed}"
                           HorizontalContentAlignment="Center"
                           VerticalContentAlignment="Center"
                           PressedBackgroundBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=CaptionButton_PressedStateBackgroundBrush}}"
                           PressedBorderBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=CaptionButton_PressedStateBorderBrush}}"
                           Margin="0,1" 
                           x:Name="PART_RibbonChrome">
            <Rectangle  Fill="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=BackgroundBrushForCaptionButton}}" 
                        RenderOptions.BitmapScalingMode="Linear" 
                        Stroke="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=BorderBrushForCaptionButton}}" 
                        StrokeThickness="1.2" 
                        RadiusX="1.1" 
                        RadiusY="1.1" 
                        HorizontalAlignment="Center"
                        Margin="0, 5.5, 0, 0"  
                        Height="4" 
                        Width="11"/>
        </ubcr:RibbonChrome>
        <ControlTemplate.Triggers>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="BorderThickness" Value="1.7" TargetName="PART_RibbonChrome"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=CloseButtonTemplate}"
                     TargetType="{x:Type ubcr:RibbonButton}">
        <ubcr:RibbonChrome InnerBorderCornerRadius="0" 
                          InnerBorderThickness="0" 
                          BorderThickness="1"
                          BorderBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=TransparentBrush}}" 
                          Background="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=TransparentBrush}}"  
                          MouseOverBorderBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=MouseOverStateBrushForCloseButton}}"  
                          RenderMouseOver="{TemplateBinding IsMouseOver}"
                          MouseOverBackgroundBrush="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=CloseButtonBackground}}"
                          HorizontalContentAlignment="Center" 
                          VerticalContentAlignment="Center"
                          RenderPressed="{TemplateBinding IsPressed}"
                          PressedBorderBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=MouseOverStateBrushForCloseButton}}"
                          x:Name="PART_RibbonChrome"
                          Margin="0,1,0,1"
                          PressedBackgroundBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=PressedStateBackgroundBrushForCloseButton}}">
            <Path Data="M0,0L2,0L4,2L6,0L8,0L8,1L6,3L8,5L8,6L6,6L4,4L2,6L0,6L0,5L2,3L0,1L0,0Z" 
                              Width="11" 
                              Height="9" 
                              StrokeThickness="1"
                              Stretch="Fill" 
                              Stroke="#FF4B4B4B" 
                              Fill="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=WhiteBrush}}" 
                              HorizontalAlignment="Center"
                              VerticalAlignment="Center"/>
        </ubcr:RibbonChrome>
        <ControlTemplate.Triggers>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="BorderThickness" Value="1.7" TargetName="PART_RibbonChrome"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--Maximize button template-->
    <ControlTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly=ubcr:RibbonWindow, ResourceId=MaximizeButtonTemplate}"
                     TargetType="{x:Type ubcr:RibbonButton}">
        <ubcr:RibbonChrome  InnerBorderCornerRadius="0" 
                           InnerBorderThickness="0"  
                           BorderThickness="1"
                           BorderBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=TransparentBrush}}" 
                           Background="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=TransparentBrush}}"  
                           MouseOverBorderBrush="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=SelectedBorderBrush}}"  
                           RenderMouseOver="{TemplateBinding IsMouseOver}"
                           MouseOverBackgroundBrush="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=SelectedTabItemBrush}}"
                           RenderPressed="{TemplateBinding IsPressed}"
                           HorizontalContentAlignment="Center"
                           VerticalContentAlignment="Center"
                           PressedBackgroundBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=CaptionButton_PressedStateBackgroundBrush}}"
                           PressedBorderBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=CaptionButton_PressedStateBorderBrush}}"
                           Margin="0,1" 
                           x:Name="PART_RibbonChrome">
            <Grid >
                <Rectangle  Fill="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=BackgroundBrushForCaptionButton}}" 
                            Stroke="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=BorderBrushForCaptionButton}}" 
                            StrokeThickness="1.2" 
                            RadiusX="1.1" 
                            RadiusY="1.1" 
                            HorizontalAlignment="Center" 
                            VerticalAlignment="Center" 
                            Height="9" 
                            Width="11"/>
                <Rectangle  Fill="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=BackgroundBrushForCaptionButton}}" 
                            Stroke="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=BorderBrushForCaptionButton}}" 
                            StrokeThickness="1.2" 
                            Margin="3"  />
            </Grid>
        </ubcr:RibbonChrome>
        <ControlTemplate.Triggers>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="BorderThickness" Value="1.7" TargetName="PART_RibbonChrome"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--Restore button template-->
    <ControlTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=RestoreButtonTemplate}"
                     TargetType="{x:Type ubcr:RibbonButton}">
        <ubcr:RibbonChrome  InnerBorderCornerRadius="0" 
                           InnerBorderThickness="0"  
                           BorderThickness="1"
                           BorderBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=TransparentBrush}}" 
                           Background="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=TransparentBrush}}"  
                           RenderMouseOver="{TemplateBinding IsMouseOver}"
                           RenderPressed="{TemplateBinding IsPressed}"
                           HorizontalContentAlignment="Center"
                           VerticalContentAlignment="Center"
                           PressedBackgroundBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=CaptionButton_PressedStateBackgroundBrush}}"
                           PressedBorderBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=CaptionButton_PressedStateBorderBrush}}"
                           MouseOverBorderBrush="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=SelectedBorderBrush}}"  
                            MouseOverBackgroundBrush="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=SelectedTabItemBrush}}"
                           Margin="0,1" >
            <Image Stretch="None">
                <Image.Source>
                    <DrawingImage >
                        <DrawingImage.Drawing>
                            <DrawingGroup>
                                <GeometryDrawing Brush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=BackgroundBrushForCaptionButton}}" 
                                         Geometry="M3.75,0 L11.25,0 L11.25,7 L3.75,7z">
                                    <GeometryDrawing.Pen>
                                        <Pen Thickness="1" 
                                             StartLineCap="Flat" 
                                             EndLineCap="Flat" 
                                             Brush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=CaptionButton_PenBrush}}"/>
                                    </GeometryDrawing.Pen>
                                </GeometryDrawing>
                                <GeometryDrawing Brush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=BackgroundBrushForCaptionButton}}" 
                                         Geometry="M5.75,3 L9.25,3 L9.25,5.5 L5.75,5.5z">
                                    <GeometryDrawing.Pen>
                                        <Pen Thickness="1" 
                                             StartLineCap="Flat" 
                                             EndLineCap="Flat" 
                                             Brush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=CaptionButton_PenBrush}}"/>
                                    </GeometryDrawing.Pen>
                                </GeometryDrawing>
                                <GeometryDrawing Brush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=BackgroundBrushForCaptionButton}}" 
                                                 Geometry="M0,3.5 L7.5,3.5 L7.5,10.5 L0,10.5z">
                                    <GeometryDrawing.Pen>
                                        <Pen Thickness="1" 
                                             StartLineCap="Flat" 
                                             EndLineCap="Flat" 
                                             Brush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=CaptionButton_PenBrush}}"/>
                                    </GeometryDrawing.Pen>
                                </GeometryDrawing>
                                <GeometryDrawing Brush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=BackgroundBrushForCaptionButton}}" 
                                         Geometry="M2,6.5 L5.5,6.5 L5.5,9 L2,9z">
                                    <GeometryDrawing.Pen>
                                        <Pen Thickness="1" 
                                             StartLineCap="Flat" 
                                             EndLineCap="Flat" 
                                             Brush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=CaptionButton_PenBrush}}"/>
                                    </GeometryDrawing.Pen>
                                </GeometryDrawing>
                            </DrawingGroup>
                        </DrawingImage.Drawing>
                    </DrawingImage>
                </Image.Source>
            </Image>
        </ubcr:RibbonChrome>
    </ControlTemplate>

    <!--Minimize button style-->
    <Style TargetType="{x:Type ubcr:RibbonButton}" 
           x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=DefaultCaptioButtonStyle}">
        <Setter Property="Width" Value="30"/>
        <Setter Property="Height" Value="20"/>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Template" Value="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=DefaultCaptioButtonTemplate}}"/>
    </Style>

    <!--Close button style-->
    <Style TargetType="{x:Type ubcr:RibbonButton}" 
           BasedOn="{StaticResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=DefaultCaptioButtonStyle}}"
           x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=CloseButtonStyle}">
        <Setter Property="Template" Value="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=CloseButtonTemplate}}"/>
    </Style>

    <!--Maximize button style-->
    <Style BasedOn="{StaticResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=DefaultCaptioButtonStyle}}" 
           TargetType="{x:Type ubcr:RibbonButton}" 
           x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=MaximizeButtonStyle}">
        <Setter Property="Template" Value="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=MaximizeButtonTemplate}}"/>
    </Style>

    <!--Restore button style-->
    <Style BasedOn="{StaticResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=DefaultCaptioButtonStyle}}" 
           TargetType="{x:Type ubcr:RibbonButton}" 
           x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=RestoreButtonStyle}">
        <Setter Property="Template" Value="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=RestoreButtonTemplate}}"/>
    </Style>

    <ControlTemplate TargetType="{x:Type ubcr:RibbonDropDownButton}" x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type ubcr:RibbonWindow}, ResourceId=WindowOptionsButtonTemplate}">
        <Grid>
            <ToggleButton Command="{TemplateBinding Command}"
                                                  CommandParameter="{TemplateBinding CommandParameter}"
                                                  CommandTarget="{TemplateBinding CommandTarget}"
                                                  Background="{TemplateBinding Background}"
                                                  BorderBrush="{TemplateBinding BorderBrush}"
                                                  ClickMode="{TemplateBinding ClickMode}"
                                                  IsChecked="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}"
                                                  FocusVisualStyle="{x:Null}">
                <ToggleButton.Template>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <ubcr:RibbonChrome x:Name="PART_RibbonChrome"
                                          RenderMouseOver="{TemplateBinding IsMouseOver}"
                                          Background="{TemplateBinding Background}" 
                                          BorderBrush="{TemplateBinding BorderBrush}"
                                          RenderPressed="{TemplateBinding IsChecked}"
                                          PressedBackgroundBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=CaptionButton_PressedStateBackgroundBrush}}"
                                          PressedBorderBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=CaptionButton_PressedStateBorderBrush}}"
                                          MouseOverBorderBrush="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=SelectedBorderBrush}}"  
                                          MouseOverBackgroundBrush="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=SelectedTabItemBrush}}"
                                          CornerRadius="0"
                                          InnerBorderCornerRadius="0">
                            <Image x:Name="image" 
                                   Width="13" 
                                   Height="10" 
                                   Grid.Column="0"  
                                   Source="{Binding Path=Image, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ubcr:RibbonDropDownButton}}}"  
                                   Margin="2, 0, 3, 0"
                                   RenderOptions.BitmapScalingMode="Linear" 
                                   Stretch="Fill" 
                                   HorizontalAlignment="Center" 
                                   VerticalAlignment="Center" />
                        </ubcr:RibbonChrome>
                    </ControlTemplate>
                </ToggleButton.Template>
            </ToggleButton>
            <Popup AllowsTransparency="True"
                   PopupAnimation="None"
                   Placement="{Binding Path=DropDownPlacement, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=OneWay, NotifyOnSourceUpdated=True}"
                   PlacementTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=OneWay, NotifyOnSourceUpdated=True}"
                   IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                   StaysOpen="False"
                   x:Name="PART_DropDownButtonPopup"
                   VerticalOffset="-4.2">
                <Border Background="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=SelectedTabItemBrush}}"
                        BorderThickness="1"
                        BorderBrush="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=DropDownBorderBrush}}"
                        Margin="7">
                    <Border.RenderTransform>
                        <TranslateTransform />
                    </Border.RenderTransform>
                    <Grid VerticalAlignment="Top"
                           x:Name="PART_RibbonDropDownButtonResize"
                           MinHeight="32.0">
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Border  Background="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=SelectedTabItemBrush}}"
                                 Effect="{DynamicResource ResourceKey={ComponentResourceKey TypeInTargetAssembly={x:Type skin:SkinManager}, ResourceId=DropDownShadowEffect}}"
                                 Grid.RowSpan="2"/>
                        <StackPanel IsItemsHost="True"
                                    KeyboardNavigation.DirectionalNavigation="Cycle"
                                    x:Name="PART_DropDownButtonItemsHost"
                                    Focusable="True"
                                    FocusVisualStyle="{x:Null}"
                                    Margin="1"/>
                    </Grid>
                </Border>
            </Popup>
        </Grid>
    </ControlTemplate>
    
</ResourceDictionary>